#!/bin/bash 
set -e

TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage3}
SRC=${SRC:-/sources}

name=python3
version=3.9.1

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/Python-$version.tar.xz -C $TMP

{ time \
   {

    cd $TMP/Python-$version
	
    CXX="/usr/bin/g++"              \
    ./configure --prefix=/usr       \
                --enable-shared     \
                --with-system-expat \
                --with-system-ffi   \
                --with-ensurepip=yes   \
				--enable-optimizations \
				--with-dbmliborder=bdb:gdbm:ndbm
    
    make
    
    make install

    install -v -dm755 /usr/share/doc/python-$version/html 

    tar --strip-components=1  \
        --no-same-owner       \
        --no-same-permissions \
        -C /usr/share/doc/python-$version/html \
        -xvf $SRC/python-$version-docs-html.tar.bz2

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
